﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Net;
using System.ServiceModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight;
using PCManagerReloaded.ServiceReference;

namespace PCManagerReloaded.Model
{
    public class FileModelProvider : ViewModelBase
    {
        public void LoadFilesAsync(Action<GetFileInformationCompletedEventArgs> action)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.GetFileInformationAsync();
                client.GetFileInformationCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void LoadNASFilesAsync(Action<GetGeGucktFileInformationCompletedEventArgs> action)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.GetGeGucktFileInformationAsync();
                client.GetGeGucktFileInformationCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void LoadPCStartUpTime(Action<GetPCStartUpTimeCompletedEventArgs> action)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.GetPCStartUpTimeAsync();
                client.GetPCStartUpTimeCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void LoadServiceStartUpTime(Action<GetStartUpTimeCompletedEventArgs> action)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.GetStartUpTimeAsync();
                client.GetStartUpTimeCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void LoadIsShutdownRequested(Action<IsShutdownRequestedCompletedEventArgs> action)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.IsShutdownRequestedAsync();
                client.IsShutdownRequestedCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void RequestShutdown(Action<AsyncCompletedEventArgs> action)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.ShutDownAsync();
                client.ShutDownCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void CancelShutdown(Action<AsyncCompletedEventArgs> action)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.CancelShutDownAsync();
                client.CancelShutDownCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void LoadLastSystemShutdown(Action<GetLastSystemShutdownCompletedEventArgs> action)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.GetLastSystemShutdownAsync();
                client.GetLastSystemShutdownCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void DeleteFileAsync(Action<AsyncCompletedEventArgs> action, ObservableCollection<ServiceReference.FileEntry> entries)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.DeleteFileEntriesAsync(entries);
                client.DeleteFileEntriesCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }

        public void MoveFileAsync(Action<AsyncCompletedEventArgs> action, ObservableCollection<ServiceReference.FileEntry> entries)
        {
            try
            {
                PcInfoServiceClient client = new PcInfoServiceClient();
                client.Endpoint.Address = new EndpointAddress(GlobalSettings.Default.ServerAddress);
                client.MarkFilesAsLookedAsync(entries);
                client.MarkFilesAsLookedCompleted += ((sender, args) => action(args));
            }
            catch (Exception exc)
            {
                //throw;
            }
        }
    }
}
